using Game.Core;
using Game.Core.Loader;
using Game.Main.Event;
using UnityEngine;

namespace Game.Main.View
{
	public class Map : EventObject
	{
		public int mapId;

		public Transform map;

		public Transform sceneLayer;

		public Transform sceneLayerItem;

		public Transform sceneLayerAudio;

		public Transform sceneLyaerFront;

		public float sceneLayerBorder;

		public Transform distLayer;

		public Transform distLayerItem;

		public Transform groundTrans;

		public override void Init()
		{
			ResourceLoader resourceLoader = new ResourceLoader("prefabs/map/map" + mapId, "Map" + mapId + ".prefab");
			resourceLoader.Bind(LoadEvent.LOAD_COMPLETE, OnResourceLoadComplete);
			resourceLoader.Load();
		}

		private void OnResourceLoadComplete(BaseEvent evt)
		{
			ResourceLoader resourceLoader = evt.sender as ResourceLoader;
			map = Object.Instantiate((GameObject)resourceLoader.resource).transform;
			map.name = "Map";
			map.localPosition = new Vector3(0f, 0f, 0f);
			sceneLayer = map.Find("SceneLayer");
			sceneLayerItem = sceneLayer.Find("Item");
			sceneLayerBorder = sceneLayer.Find("Border").position.x;
			sceneLayerAudio = sceneLayer.Find("Audio");
			sceneLayer.position = new Vector3(0f, 0f, 0f);
			sceneLayer.Find("Texture").position = new Vector3(0f, 0f, 5f);
			sceneLyaerFront = sceneLayer.Find("Texture/Front");
			if (sceneLyaerFront != null)
			{
				sceneLyaerFront.position = new Vector3(0f, 0f, 0f);
			}
			distLayer = map.Find("DistLayer");
			distLayerItem = distLayer.Find("Item");
			groundTrans = map.Find("Ground");
			resourceLoader.Destroy();
			Fire(new BaseEvent(LoadEvent.LOAD_COMPLETE));
		}

		public void UpdateLayerPosition(float scale)
		{
		}

		public void ClearMap()
		{
			if (map != null)
			{
				Object.Destroy(map.gameObject);
				map = null;
			}
		}
	}
}
